home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
MacApp
/
MacApp 3.0a2
/
Libraries
/
UCommand.cp
< prev
next >
Wrap
Text File
|
1991-05-01
|
14KB
|
509 lines
// UCommand.cp
/* Copyright © 1985-1991 by Apple Computer, Inc. All rights reserved. */
#ifndef __UCOMMAND__
#include <UCommand.h>
#endif
#ifndef __STDIO__
#include <StdIo.h>
#endif
#ifndef __UGEOMETRY__
#include <UGeometry.h>
#endif
#ifndef __UAPPLEEVENTS__
#include <UAppleEvents.h>
#endif
#ifndef __UDOCUMENT__
#include <UDocument.h>
#endif
#ifndef __UAPPLICATION__
#include <UApplication.h>
#endif
#ifndef __USCROLLER__
#include <UScroller.h>
#endif
#ifndef __UMACAPPUTILITIES__
#include <UMacAppUtilities.h>
#endif
#ifndef __UMACAPPGLOBALS__
#include <UMacAppGlobals.h>
#endif
#ifndef __UMEMORY__
#include <UMemory.h>
#endif
#ifndef __UERRORMGR__
#include <UErrorMgr.h>
#endif
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TCommand::ICommand(CmdNumber itsCmdNumber,
TObject* notify,
TView* itsView)
{
this->IEvent(itsCmdNumber,NULL,gApplication);
fID = itsCmdNumber;
fChangedObject = notify;
fView = itsView;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TCommand::Initialize(void) // override
{
inherited::Initialize();
fChangedObject = NULL;
fCmdDone = FALSE;
fCanUndo = TRUE;
fCausesChange = TRUE;
fChangesClipboard = FALSE;
fFreeOnCompletion = TRUE; // command will be freed after DoIt or Commit
fRecurring = FALSE; // Command is a one-shot deal
fReadyToExecute = TRUE; // Always executable by default
fView = NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TCommand::Commit(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TCommand::DoIt(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal ChangeID TCommand::GetChangeID(void)
{
if (fCmdDone)
return fID;
else
return cUndo;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal Boolean TCommand::IsReadyToExecute(void) // override
{
return fReadyToExecute;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal Boolean TCommand::IsRecurring(void) // override
{
return fRecurring;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TCommand::RedoIt(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal Boolean TCommand::ShouldFreeOnCompletion(void)// override
{
return fFreeOnCompletion;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TCommand::UndoIt(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TCommand::Process(void)
{
TEvtHandler* handler = this->GetHandler();
if (handler)
handler->PerformCommand(this);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAFields
pascal void TCommand::Fields(TObject* obj) // override
{
obj->DoToField("TCommand", (Ptr)NULL, bClass);
obj->DoToField("fCanUndo", (Ptr) & fCanUndo, bBoolean);
obj->DoToField("fCausesChange", (Ptr) & fCausesChange, bBoolean);
obj->DoToField("fChangedObject", (Ptr) & fChangedObject, bObject);
obj->DoToField("fChangesClipboard", (Ptr) & fChangesClipboard, bBoolean);
obj->DoToField("fCmdDone", (Ptr) & fCmdDone, bBoolean);
obj->DoToField("fFreeOnCompletion", (Ptr) & fFreeOnCompletion, bBoolean);
obj->DoToField("fReadyToExecute", (Ptr) & fReadyToExecute, bBoolean);
obj->DoToField("fRecurring", (Ptr) & fRecurring, bBoolean);
obj->DoToField("fView", (Ptr) & fView, bObject);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TNoChangesCommand::INoChangesCommand(CmdNumber itsCmdNumber,
TObject* notify,
TView* itsView)
{
this->ICommand(itsCmdNumber, notify, itsView);
// we said NO changes
fCanUndo = FALSE;
fCausesChange = FALSE;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAFields
pascal void TNoChangesCommand::Fields(TObject* obj)// override
{
obj->DoToField("TNoChangesCommand", (Ptr)NULL, bClass);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TTracker::Initialize(void) // override
{
inherited::Initialize();
fConstrainsMouse = FALSE;
fInitialPt = gZeroVPt;
fScroller = NULL;
fTrackNonMovement = FALSE;
fTracksMouse = TRUE; // After all, we came here to track the mouse.
fViewConstrain = TRUE;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TTracker::ITracker(CmdNumber itsCmdNumber,
TObject* notify,
TView* itsView,
TScroller* itsScroller,
const VPoint& itsMouse)
{
this->ICommand(itsCmdNumber, notify, itsView);
fInitialPt = itsMouse;
fScroller = itsScroller;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TTracker::AutoScroll(const VPoint& delta)
{
if (fScroller)
fScroller->ScrollBy(delta, kRedraw);
else
{
//??? any sensible behaviour here?
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal Boolean TTracker::IsDoneTracking(void)
{
if (fView)
return fView->IsDoneTracking();
else
//??? Would it be better to let the application have a crack at it here?
return !StillDown();
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TTracker::Process(void) // OVERRIDE
{
TCommand* finalCommand = NULL;
TEvtHandler* handler = NULL;
#if qDebug
MAName aMAName;
#endif
if (this->fTracksMouse)
{
#if qDebugMsg
if (gIntenseDebugging && this)
{
this->GetClassName(aMAName);
fprintf(stderr, "Tracking Command: %s\n", (char *) aMAName);
}
#endif
if (gApplication->fEventLevel == 1) // Don't unload segs if in nested event handling
UnloadAllSegments();
finalCommand = gApplication->TrackMouse(fInitialPt.Copy(), gStdHysteresis, this);
if (finalCommand)
{
handler = finalCommand->GetHandler();
if (handler)
handler->PerformCommand(finalCommand);
}
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TTracker::TrackConstrain(TrackPhase aTrackPhase,
const VPoint& anchorPoint,
const VPoint& previousPoint,
VPoint& nextPoint,
Boolean mouseDidMove)
{
if (fView)
fView->TrackConstrain(aTrackPhase, anchorPoint, previousPoint, nextPoint, mouseDidMove);
else
{
//??? should this call back into an application method if there is no view?
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal void TTracker::TrackFeedback(TrackPhase aTrackPhase,
const VPoint& anchorPoint,
const VPoint& previousPoint,
const VPoint& nextPoint,
Boolean mouseDidMove,
Boolean turnItOn)
{
if (fView)
fView->TrackFeedback(aTrackPhase, anchorPoint, previousPoint, nextPoint, mouseDidMove, turnItOn);
else
{
//??? should this call back into an application method if there is no view?
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MADoCommand
pascal TTracker* TTracker::TrackMouse(TrackPhase aTrackPhase,
VPoint& anchorPoint,
VPoint& previousPoint,
VPoint& nextPoint,
Boolean mouseDidMove)
{
if (fView)
fView->TrackMouse(aTrackPhase, anchorPoint, previousPoint, nextPoint, mouseDidMove);
else
{
//??? should this call back into an application method if there is no view?
}
if ((aTrackPhase == trackRelease) && ((fView == NULL) ||!(fView->ContainsMouse(nextPoint))))
return NULL;
else
return this;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAFields
pascal void TTracker::Fields(TObject* obj) // override
{
obj->DoToField("TTracker", (Ptr)NULL, bClass);
obj->DoToField("fConstrainsMouse", (Ptr) & fConstrainsMouse, bBoolean);
obj->DoToField("fInitialPt", (Ptr) & fInitialPt, bVPoint);
obj->DoToField("fScroller", (Ptr) & fScroller, bObject);
obj->DoToField("fTrackNonMovement", (Ptr) & fTrackNonMovement, bBoolean);
obj->DoToField("fTracksMouse", (Ptr) & fTracksMouse, bBoolean);
obj->DoToField("fViewConstrain", (Ptr) & fViewConstrain, bBoolean);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TNoChangesTracker::INoChangesTracker(CmdNumber itsCmdNumber,
TObject* notify,
TView* itsView,
TScroller* itsScroller,
const VPoint& itsMouse)
{
this->ITracker(itsCmdNumber, notify, itsView, itsScroller, itsMouse);
// we said NO changes
fCanUndo = FALSE;
fCausesChange = FALSE;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAFields
pascal void TNoChangesTracker::Fields(TObject* obj)// override
{
obj->DoToField("TNoChangesTracker", (Ptr)NULL, bClass);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MASelCommand
pascal void TAppleCommand::IAppleCommand(CmdNumber itsCmdNumber,
TDocument* itsDocument,
TView* itsView)
{
this->ICommand(itsCmdNumber, itsDocument, itsView);
}
//--------------------------------------------------------------------------------------------------
#pragma segment MASelCommand
pascal void TAppleCommand::InitFromAppleEvent(CmdNumber itsCmdNumber,
TDocument* itsDocument,
TView* itsView,
const AppleEvent& itsMessage,
const AppleEvent& itsReply)
{
FailInfo fi;
this->IAppleCommand(itsCmdNumber, itsDocument, itsView);
if (fi.Try())
{
fMessage = new TAppleEvent;
fMessage->InitFromMessage(itsMessage);
fReply = new TAppleEvent;
fReply->InitFromMessage(itsReply);
// Inform the AppleEvent manager that this event will be processed asynchronously.
// The corresponding resume will occur in TAppleCommand::Free().
FailOSErr(AESuspendTheCurrentEvent(itsMessage));
fi.Success();
}
else // Recover
{
fMessage = (TAppleEvent *)FreeIfObject(fMessage);
fReply = (TAppleEvent *)FreeIfObject(fReply);
fi.ReSignal();
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MASelCommand
pascal void TAppleCommand::Initialize(void) // override
{
inherited::Initialize();
// By default, commands that handle AppleEvents are not undoable.
// Does it ever make sense for them to be undoable ???
fCanUndo = FALSE;
fMessage = NULL;
fReply = NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAClose
pascal void TAppleCommand::Free(void) // override
{
if (fMessage && fReply)
{
AppleEvent theMessage = fMessage->fMessage;
AppleEvent theReply = fReply->fMessage;
// Inform the AppleEvent manager that we are through processing the event. If an error
// has occurred the default reply will contain the error number and error string.
AEResumeTheCurrentEvent(theMessage, theReply, (EventHandlerProcPtr)kAENoDispatch, 0);
fMessage = (TAppleEvent *)FreeIfObject(fMessage);
fReply = (TAppleEvent *)FreeIfObject(fReply);
}
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TAppleCommand::ReportError(OSErr error, long)
{
if (fReply)
{
Str255 errStr;
// Inform the AppleEvent manager that an error occured while processing
// the event. We will try to be as helpful as possible as to what went
// wrong by returning the error number and the best possible string. The
// ResumeEvent will occur when the command is freed.
LookupErrString(error, errReasonID, errStr);
fReply->WriteLong('errn', (long)error);
fReply->WriteString('errs', errStr);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment MACommandRes
pascal void TAppleCommand::SendIt(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAFields
pascal void TAppleCommand::Fields(TObject* obj) // override
{
obj->DoToField("TAppleCommand", (Ptr)NULL, bClass);
obj->DoToField("fMessage", (Ptr) & fMessage, bObject);
obj->DoToField("fReply", (Ptr) & fReply, bObject);
inherited::Fields(obj);
}